package com.chuanjiabao.wisdom.util.dialog;

import android.content.Context;
import android.databinding.DataBindingUtil;
import android.view.LayoutInflater;
import android.view.View;

import com.chuanjiabao.wisdom.R;
import com.chuanjiabao.wisdom.databinding.DialogVersionHintBinding;
import com.chuanjiabao.wisdom.databinding.DialogWxHintBinding;
import com.chuanjiabao.wisdom.listener.OnBHClickListener;
import com.flyco.dialog.widget.base.BaseDialog;

/**
 * Created by 86178 on 2019/8/16.
 * author mogen
 * 用心，成就一切。
 */

public class VersionDialog extends BaseDialog {

    private Context context;
    private DialogVersionHintBinding binding;
    private boolean isCancel;
    private OnBHClickListener onBHClickListener;

    public VersionDialog(Context context) {
        this(context, true);
    }

    public VersionDialog(Context context, boolean isCancel) {
        super(context);
        this.context = context;
        this.isCancel = isCancel;

        binding = DataBindingUtil.inflate(
                LayoutInflater.from(context),
                R.layout.dialog_version_hint,
                null,
                false
        );
        binding.setDialog(this);
    }

    @Override
    public View onCreateView() {
        widthScale(0.75f);
        return binding.getRoot();
    }

    @Override
    public void setUiBeforShow() {
        setCancelable(isCancel);
        setCanceledOnTouchOutside(isCancel);

        if (!isCancel) {
            binding.dialogNo.setVisibility(View.GONE);
            binding.tvModuleDivider.setVisibility(View.GONE);
        }
    }

    public VersionDialog setTitle(String title) {
        binding.tvModuleTitle.setText(title);
        return this;
    }

    public VersionDialog setContent(String content) {
        binding.tvModuleContent.setText(content);
        return this;
    }

    public VersionDialog setYesHint(String hint) {
        binding.dialogYes.setText(hint);
        return this;
    }

    public VersionDialog setNoHint(String hint) {
        binding.dialogNo.setText(hint);
        return this;
    }

    public VersionDialog setForce(boolean isForce) {
        this.isCancel = !isForce;
        setUiBeforShow();
        return this;
    }

    public VersionDialog setOnBHClickListener(OnBHClickListener onBHClickListener) {
        this.onBHClickListener = onBHClickListener;
        return this;
    }

    public void noPoint(View view) {
        if (onBHClickListener != null) {
            onBHClickListener.onCloseClick();
        }
        dismiss();
    }

    public void okPoint(View view) {
        if (onBHClickListener != null) {
            onBHClickListener.onConfirmClick();
        }
        if (isCancel) dismiss();
    }

}


